package com.yangrd.airship.generator.support.impl;

import lombok.RequiredArgsConstructor;

import java.io.*;

/**
 * @author yangrd
 * @date 2021/11/8
 */
@RequiredArgsConstructor
public class FilePageGeneratorWriter extends AbstractPageGeneratorWriter {

    private final String outFilePath;

    @Override
    public Writer getWriter(TableGeneratorWriterContext context) {
        try {
            File dir = new File(outFilePath + context.getPath());
            if (!dir.exists()) {
                dir.mkdir();
            }
            return new OutputStreamWriter(new FileOutputStream(new File(outFilePath + context.getPath() + "/" + context.getFullName())));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
